package org.apache.commons.io.input;

import com.sutuijingling.result.WorkStatus;
import java.io.Closeable;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import org.apache.commons.io.b;
import org.apache.commons.io.c;

public class a implements Runnable {
    private final byte[] a;
    private final File b;
    private final long c;
    private final boolean d;
    private final TailerListener e;
    private final boolean f;
    private volatile boolean g;

    private long a(RandomAccessFile randomAccessFile) throws IOException {
        StringBuilder stringBuilder = new StringBuilder();
        long filePointer = randomAccessFile.getFilePointer();
        int i = 0;
        long j = filePointer;
        while (this.g) {
            int read = randomAccessFile.read(this.a);
            if (read != -1) {
                for (int i2 = 0; i2 < read; i2++) {
                    byte b = this.a[i2];
                    switch (b) {
                        case (byte) 10:
                            this.e.handle(stringBuilder.toString());
                            stringBuilder.setLength(0);
                            filePointer = (((long) i2) + j) + 1;
                            i = 0;
                            break;
                        case WorkStatus.ItemMakeOrder /*13*/:
                            if (i != 0) {
                                stringBuilder.append('\r');
                            }
                            i = 1;
                            break;
                        default:
                            if (i != 0) {
                                this.e.handle(stringBuilder.toString());
                                stringBuilder.setLength(0);
                                filePointer = (((long) i2) + j) + 1;
                                i = 0;
                            }
                            stringBuilder.append((char) b);
                            break;
                    }
                }
                j = randomAccessFile.getFilePointer();
            } else {
                randomAccessFile.seek(filePointer);
                return filePointer;
            }
        }
        randomAccessFile.seek(filePointer);
        return filePointer;
    }

    public void run() {
        Exception e;
        RandomAccessFile randomAccessFile;
        long j;
        Closeable closeable;
        Throwable th;
        Exception exception;
        Object obj;
        Throwable th2;
        Closeable closeable2 = null;
        long j2 = 0;
        long j3 = 0;
        while (this.g && r1 == null) {
            try {
                closeable2 = new RandomAccessFile(this.b, "r");
            } catch (FileNotFoundException e2) {
                try {
                    this.e.fileNotFound();
                } catch (Exception e3) {
                    e = e3;
                }
            }
            if (closeable2 == null) {
                try {
                    Thread.sleep(this.c);
                } catch (InterruptedException e4) {
                }
            } else {
                j2 = this.d ? this.b.length() : 0;
                j3 = System.currentTimeMillis();
                closeable2.seek(j2);
            }
        }
        while (this.g) {
            boolean a = b.a(this.b, j3);
            long length = this.b.length();
            if (length < j2) {
                this.e.fileRotated();
                try {
                    randomAccessFile = new RandomAccessFile(this.b, "r");
                    try {
                        c.a(closeable2);
                        j2 = 0;
                        closeable2 = randomAccessFile;
                    } catch (FileNotFoundException e5) {
                        Object obj2 = randomAccessFile;
                        j = 0;
                        try {
                            this.e.fileNotFound();
                            closeable2 = closeable;
                            j2 = j;
                        } catch (Exception e6) {
                            e = e6;
                            closeable2 = closeable;
                        } catch (Throwable th3) {
                            th = th3;
                            closeable2 = closeable;
                        }
                    } catch (Exception e7) {
                        exception = e7;
                        obj = randomAccessFile;
                        e = exception;
                    } catch (Throwable th4) {
                        th2 = th4;
                        obj = randomAccessFile;
                        th = th2;
                    }
                } catch (FileNotFoundException e8) {
                    long j4 = j2;
                    closeable = closeable2;
                    j = j4;
                    this.e.fileNotFound();
                    closeable2 = closeable;
                    j2 = j;
                }
            } else {
                if (length > j2) {
                    j2 = a(closeable2);
                    j3 = System.currentTimeMillis();
                } else if (a) {
                    closeable2.seek(0);
                    j2 = a(closeable2);
                    j3 = System.currentTimeMillis();
                }
                if (this.f) {
                    c.a(closeable2);
                }
                try {
                    Thread.sleep(this.c);
                } catch (InterruptedException e9) {
                }
                if (this.g && this.f) {
                    randomAccessFile = new RandomAccessFile(this.b, "r");
                    try {
                        randomAccessFile.seek(j2);
                    } catch (Exception e72) {
                        exception = e72;
                        obj = randomAccessFile;
                        e = exception;
                    } catch (Throwable th42) {
                        th2 = th42;
                        obj = randomAccessFile;
                        th = th2;
                    }
                } else {
                    Closeable closeable3 = closeable2;
                }
                closeable2 = randomAccessFile;
            }
        }
        c.a(closeable2);
        return;
        try {
            this.e.handle(e);
            c.a(closeable2);
        } catch (Throwable th5) {
            th = th5;
            c.a(closeable2);
            throw th;
        }
    }
}
